Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body onhashchange="myFunction(event)"> <p>Click the button to change the anchor part (hash) of the current URL to #part5</p> <p>The oldURL property returns the URL of the document we navigated away from.</p> <p>The newURL property returns the URL we are navigating to.</p> <button onclick="changePart()">Try it</button> <p><strong>Note:</strong> These properties are not supported in Internet Explorer.</p> <p id="demo"></p> <script> // Using the location.hash property to change the anchor part function changePart() { location.hash = "part5"; } function myFunction() { document.getElementById("demo").innerHTML = "Previous URL: " + event.oldURL + "<br>New URL: " + event.newURL; } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_hashchange_newurl by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:30:45 GMT --> </html>
Result:
Try it Yourself - © w3schools.com